package unamed.level;

import basis.game.entities.Entity;
import basis.game.level.Level;
import basis.game.level.Terrain;
import basis.game.main.Renderable;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Room implements Level{

    private double x,y,w,h;
    private boolean show=true;
    private Terrain[] terrain;
    private Entity[] entities;
    
    public Room(double x,double y,double w,double h){
        this.x=x;
        this.y=y;
        this.w=w;
        this.h=h;
        terrain=new Terrain[(int)(w*h/Tile.SIZE*Tile.SIZE)];
    }
    
    @Override
    public double getWidth(){
        return w;
    }
    
    @Override
    public double getHeight(){
        return h;
    }
    
    @Override
    public List<Renderable> getObjects(){
        ArrayList<Renderable> a=new ArrayList<Renderable>();
        a.addAll(Arrays.asList(terrain));
        a.addAll(Arrays.asList(entities));
        return a;
    }
    
    @Override
    public Terrain[] getTerrain() {
        return terrain;
    }

    @Override
    public Entity[] getEntities() {
        return entities;
    }

    @Override
    public Terrain getTerrainAt(double x,double y) {
        double ax=Math.round((x-this.x)/Tile.SIZE)*Tile.SIZE;
        double ay=Math.round((y-this.y)/Tile.SIZE)*Tile.SIZE;
        return terrain[(int)(ax+ay*w/Tile.SIZE)];
    }

    @Override
    public double getTerrainSize() {
        return Tile.SIZE;
    }

    @Override
    public void setX(double x) {
        this.x=x;
    }

    @Override
    public void setY(double y) {
        this.y=y;
    }

    @Override
    public void move(double x, double y) {
        this.x+=x;
        this.y+=y;
    }

    @Override
    public void update(long t) {
        
    }

    @Override
    public void render(Graphics2D g) {
        g.setColor(Color.lightGray);
        g.fillRect((int)x,(int)y,(int)w,(int)h);
    }

    @Override
    public double getX() {
        return x;
    }

    @Override
    public double getY() {
        return y;
    }

    @Override
    public Shape getBounds() {
        return null;
    }

    @Override
    public void show(boolean s) {
        show=s;
    }

    @Override
    public boolean isShown() {
        return show;
    }
    
}